var http= require('http');
var port= (process.env.VMC_APP_port|| 3000);
var host= (process.env.VCAP_APP_HOST|| 'localhost');
//var open= require('open');
//https://cnodejs.org/topic/55045a5173263b0e4eef9c86
var url= require('url');
var fs= require('fs');
var util= require('util');

function start(){
    function onRequest(request, response){
        console.log('request has been received~')
        response.writeHead(200,{'Content-Type': 'text/html'})
        var path= url.parse(request.url).pathname;
        console.log(path)
        fs.readFile('.'+ path, 'utf-8', function(err, data){
            if(err){
//                response.write(util.inspect(err, true))
//                response.end(path)
                response.write("404 not found from happy women's day~")
                response.end()
            }else{
                response.write(data)
                response.end()
            }
        })
    }
    http.createServer(onRequest).listen(port, host)
    console.log('server has been started~')
//    open('./static/')
}

exports.start= start;